﻿//-----------------------------------------------------------------------
// <copyright file="Project.cs" company="Microsoft Corporation">
//     Copyright Microsoft Corporation. All Rights Reserved. This code released under the terms of the Microsoft Public License (MS-PL, http://opensource.org/licenses/ms-pl.html.) This is sample code only, do not use in production environments.
// </copyright>
//-----------------------------------------------------------------------
namespace Microsoft.ALMRangers.VsarTreasureMap.WindowsStoreApp.Models
{
    using Microsoft.ALMRangers.VsarTreasureMap.WindowsStoreApp.Extensions;

    /// <summary>
    /// Class defining the project data type for this application.
    /// </summary>
    public class Project
    {
        /// <summary>
        /// Gets or sets the Unique Identifier for the project
        /// </summary>
        /// <value>The id.</value>
        public int Id { get; set; }

        /// <summary>
        /// Gets or sets the Name representation of the project.
        /// </summary>
        /// <value>The name.</value>
        public string Name { get; set; }

        /// <summary>
        /// Gets or sets the Image representation of the project.
        /// </summary>
        /// <value>The image.</value>
        public string Image { get; set; }

        /// <summary>
        /// Gets or sets the Description of the project.
        /// </summary>
        /// <value>The description.</value>
        public string Description { get; set; }

        /// <summary>
        /// Gets the truncated description for the snapped view.
        /// </summary>
        /// <value>The short description.</value>
        public string ShortDescription
        {
            get
            {
                return this.Description.TruncateAtWord(60);
            }
        }

        /// <summary>
        /// Gets or sets the Order of the project.
        /// </summary>
        /// <value>The order.</value>
        public int Order { get; set; }

        /// <summary>
        /// Gets or sets the Category that this project falls within.
        /// </summary>
        /// <value>The category.</value>
        public int Category { get; set; }

        /// <summary>
        /// Gets or sets the Array of Guidance that this contained within this project.
        /// </summary>
        /// <value>The guidance.</value>
        public Guidance[] Guidance { get; set; }

        /// <summary>
        /// Gets a value indicating whether this instance is favourite.
        /// </summary>
        /// <value><c>true</c> if this instance is favourite; otherwise, <c>false</c>.</value>
        public bool IsFavourite
        {
            get
            {
                return Favourites.IsFavourite(this.Id, FavouriteType.Project);
            }
        }

        /// <summary>
        /// Gets a value indicating whether this instance is started.
        /// </summary>
        /// <value><c>true</c> if this instance is started; otherwise, <c>false</c>.</value>
        public bool IsStarted
        {
            get
            {
                var done = App.Database.StatusManager.GetCompletedDocumentCount(this.Id);
                var total = App.Database.StatusManager.GetProjectDocumentCount(this.Id);
                return done > 0 && done < total;
            }
        }

        /// <summary>
        /// Gets a value indicating whether this instance is completed.
        /// </summary>
        /// <value><c>true</c> if this instance is completed; otherwise, <c>false</c>.</value>
        public bool IsCompleted
        {
            get
            {
                var done = App.Database.StatusManager.GetCompletedDocumentCount(this.Id);
                var total = App.Database.StatusManager.GetProjectDocumentCount(this.Id);
                return done == total;
            }
        }
    }
}
